#!/bin/bash

#cpu空闲率
cpu_idle_num=$(top -bn 1|grep "^%Cpu"|awk -F '[ ,]+' '{print $8}')

#100 - 空闲率=使用率
cpu_used_num=$( echo "100 - $cpu_idle_num"|bc)

#判断cpu的使用率是否超过70%
flag=$(echo "$cpu_used_num >= 70"|bc)
if  (( $flag == 1 ));then
	echo "$(date +%Y%m%d%H%M%S) $(hostname) cpu使用率是 ${cpu_used_num}%" |tee -a /var/log/monitor_cpu.log
else
	echo "$(date +%Y%m%d%H%M%S) $(hostname) cpu使用率是 ${cpu_used_num}%"
fi


